import {reqCategoryList,reqGetBannerList,reqFloorList} from '@/api'


//home模块的小仓库
//处理action，可以书写自己的业务逻辑，也可以处理异步
const actions ={
    //通过API里面的接口函数调用，向服务器发请求，获取服务器数据
    async categoryList(context){
        let result = await reqCategoryList();
        if(result.code===200){
            context.commit('CATEGORYLIST',result.data)
        }
    },
    //获取轮播图
    async getBannerList(context){
        let result = await reqGetBannerList();
        
        if(result.code===200){
            context.commit('GETBANNERLIST',result.data)
        }
    },
    async getFloorList(context){
        let result = await reqFloorList();
        
        if(result.code===200){
            context.commit('GETFLOORLIST',result.data)
        }
    }
};
//修改state的唯一手段
const mutations ={
    CATEGORYLIST(state,categoryList){
        state.categoryList=categoryList.slice(0,16)
    },
    GETBANNERLIST(state,bannerList){
        state.bannerList=bannerList;
    },
    GETFLOORLIST(state,floorList){
        state.floorList=floorList;
    }
    
};
const state ={
    //state中数据默认初始值别瞎写，服务器返回对象，
    categoryList:[],
    bannerList:[],
    floorList:[]
};
//理解为计算属性，用于简化仓库数据，让组件获取仓库的数据更加方便
const getters ={};

export default {
    namespaced:true,
    state,
    mutations,
    actions,
    getters
}